package com.fms.controllers;

import com.fms.dao.CashbookDAO;
import com.fms.model.CashbookModel;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;

public class Cashbook extends WebPage {
	
	private Model cashbook_idModel = new Model();
	private Model org_idModel = new Model();
	private Model dateModel = new Model();
	private Model particularsModel = new Model();
	private Model receivedModel = new Model();
	private Model disbursedModel = new Model();
	private Model balanceModel = new Model();
	private Model uploaderModel = new Model();
	private Model date_createdModel = new Model();
	
	public Cashbook(){
		
		Form cashbookForm = new Form ("cashbookForm");
		
		TextField cashbook_id = new TextField ("cashbook_id", cashbook_idModel);
		cashbook_id.setRequired(true);
		cashbookForm.add(cashbook_id);
		
		TextField org_id = new TextField ("org_id", org_idModel);
		org_id.setRequired(true);
		cashbookForm.add(org_id);
		
		TextField date = new TextField ("date", dateModel);
		date.setRequired(true);
		cashbookForm.add(date);
		
		TextField particulars = new TextField ("particulars", particularsModel);
		particulars.setRequired(true);
		cashbookForm.add(particulars);
		
		TextField received = new TextField ("received", receivedModel);
		received.setRequired(true);
		cashbookForm.add(received);
		
		TextField disbursed = new TextField ("disbursed", disbursedModel);
		disbursed.setRequired(true);
		cashbookForm.add(disbursed);
		
		TextField balance = new TextField ("balance", balanceModel);
		balance.setRequired(true);
		cashbookForm.add(balance);
		
		TextField uploader = new TextField ("uploader", uploaderModel);
		uploader.setRequired(true);
		cashbookForm.add(uploader);
		
		TextField date_created = new TextField ("date_created", date_createdModel);
		date_created.setRequired(true);
		cashbookForm.add(date_created);
		
		add(cashbookForm);
		
		Button cashbookFormAdd = new Button ("cashbookFormAdd"){
			
			public void onSubmit(){
				String ncashbook_id = (String) cashbook_idModel.getObject();
				String norg_id = (String) org_idModel.getObject();
				String date = (String) dateModel.getObject();
				String particulars = (String) particularsModel.getObject();
				String nreceived = (String) receivedModel.getObject();
				String ndisbursed = (String) disbursedModel.getObject();
				String nbalance = (String) balanceModel.getObject();
				String uploader = (String) uploaderModel.getObject();
				String date_created = (String) date_createdModel.getObject();
				
				int cashbook_id = Integer.parseInt(ncashbook_id);
				int org_id = Integer.parseInt(norg_id);
				float received = Float.valueOf(nreceived);
				float disbursed = Float.valueOf(ndisbursed);
				float balance = Float.valueOf(nbalance);
				
				CashbookModel cashbook = new CashbookModel(cashbook_id, org_id, date, particulars, received, disbursed, balance, uploader, date_created);
				
				CashbookDAO cashbookDAO = new CashbookDAO();
				cashbookDAO.insert(cashbook);
			}
		};
	}
	

}
